<?php
namespace Shopiuu\Model;

use Shopiuu\Http\RequestCore;

class ShippingArea extends Model{
    
    public function __construct($accessToken, $endpoint)
    {
        parent::__construct($accessToken, $endpoint);
    }

    /**
     * Create Shipping Area
     * @param array $params array(
        "name"=> "USA" //配送区域名称
        "description"=> "description" //描述
        "areas"=> array(
                array(
                    "country_id"=> 1 //必填
                    "state_id"=> 1 //选填
                )
                ...
            )
        ) //选填
     * @return ResponseCore
     */
    public function add($params)
    {
        $request = $this->getRequest('/openApi/shippingArea/add');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Modify Shipping Area
     * @param array $params array(
        "name"=> "USA" //配送区域名称
        "description"=> "description" //描述
        "areas"=> array(
                array(
                    "country_id"=> 1 //必填
                    "state_id"=> 1 //选填
                )
                ...
            )
        ) //选填
     * @return ResponseCore
     */
    public function update($params)
    {
        $request = $this->getRequest('/openApi/shippingArea/update');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Get Shipping Area
     * @param array $params array(
        "pagenum"=> 1 //页码
        "pagesize"=> 20 //每页数量
        "search"=> "keywords" //搜索标题
        "orderfeild"=> "id" //排序字段
        "ordersort"=> "desc" //排序方式
     )
     * @return ResponseCore
     */
    public function getList($params)
    {
        $request = $this->getRequest('/openApi/shippingArea/lists');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }
    
    /**
     * Delete Shipping Area
     * @param array $params array("id"=>"25")
     * @return ResponseCore
     */
    public function delete($params)
    {
        $request = $this->getRequest('/openApi/shippingArea/delete');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

}